﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Person {
public:
	virtual void BuyTicket() {
		cout << "买票全价" << endl; }
private:
	string _name;
	};
	class Student : public Person {
	public:
		virtual void BuyTicket() {
			cout << "买票打折" << endl; }
	private:
		string _id;
		};
		class Soldier : public Person {
		public:
			virtual void BuyTicket() {
				cout << "买票优先	" << endl; }
		private:
			string _codename;
	};
			void Func(Person* ptr)
			{
				// 这⾥可以看到虽然都是Person指针Ptr在调⽤BuyTicket
					// 但是跟ptr没关系，⽽是由ptr指向的对象决定的。

					ptr->BuyTicket();
			}
			
int main()
			{
				Person ps;
				Student st;
				Soldier sr;
				Func(&ps);
				Func(&st);
				Func(&sr);
				return 0;
	}
				